package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Working;
import service.WorkingService;

import java.util.List;

@Controller
public class WorkingController {
    @Autowired
    private WorkingService workingService;
    @GetMapping("List")
    public String list(Model model){
        List<Working> list = workingService.list();
        model.addAttribute("list",list);
        return "List";
    }


    @GetMapping("toAdd")
    public String toAdd(){
        return "Add";
    }
    @PostMapping("Add")
    public String Add(Working working){
        int add = workingService.add(working);
        if (add>0){
            return "redirect:List";
        }
        return null;
    }
    @GetMapping("select/{id}")
    public String select(@PathVariable("id")Integer id, Model model){
        Working select = workingService.select(id);
        model.addAttribute("list",select);
        return "Select";
    }

}
